﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebChat.Admin
{
    public partial class CreateChannel : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ButtonCreateChannel_OnClick(object sender, EventArgs args)
        {
            Page.Validate();
            if (Page.IsValid)
            {
                WebChatDAL.WebChatDAO dao = new WebChatDAL.WebChatDAO();

                string channelName = this.TextBoxChannelName.Text.Trim();

                WebChatDAL.Channel channel;
                if (dao.TryGetChannelByChannelName(channelName, out channel))
                {
                    this.LiteralError.Text = "Sorry, channel name taken.";
                    return;
                }

                channel = dao.CreateChannel(channelName);

                Response.Redirect("ChannelCreateSuccess.aspx?channelId=" + channel.ChannelId);
            }
        }
    }
}